# coding:utf-8
import sys, time
import pytest
from selenium import webdriver

from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By

from YeMao import setting


class BroDriver(object):
    def __init__(self):
        try:
            self.wd = webdriver.Chrome(setting.WEBDRIVERURI)  # 加载浏览器
        except Exception as e:
            print("浏览加载失败:\n", e, "\n")
            sys.exit(1)  # 浏览器加载失败后直接结束进程
        self.wd.maximize_window()  # 设置浏览器最大化运行
        self.wd.implicitly_wait(10)  # 隐式等待10秒,等待页面加载完

    def run(self, url):
        self.wd.get(url)
        self.page_source = self.wd.page_source
        self.title = self.wd.title
        print(self.page_source)

    def titleis(self, title):
        pass

    def close(self):
        self.wd.quit()  # 结束浏览器


def login(bd, *args, **kwargs):
    bd.wd.find_element(args[0],args[1],args[2])
    # bd.wd.find_element_by_id('login_account').send_keys(setting.USERNAME)
    # bd.wd.find_element_by_id('login_pwd').send_keys(setting.PASSWORD)
    # bd.wd.find_element_by_css_selector('[class="lg_btn bd-radius-max"]').send_keys(Keys.ENTER)


if __name__ == '__main__':
    bd = BroDriver()
    bd.run("https://yun.yemaogj.com/login")
    login(bd,By.ID,'login_account',setting.USERNAME)
    bd.titleis('数据概括')

    time.sleep(3)

    bd.close()
